package gui.bf3;

import javax.swing.Action;
import javax.swing.Icon;

import transparent.TransparentCheckBox;
import file.SettingsDefinition;
import file.ValueObject;

public class BF3CheckBox extends TransparentCheckBox implements BF3Setting{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8446835220148582973L;
	
	protected SettingsDefinition settingsDefinition;
	
	
	public BF3CheckBox(SettingsDefinition settingsDefinition) {
		super();
		this.settingsDefinition = settingsDefinition;
	}




	public BF3CheckBox(SettingsDefinition settingsDefinition, Action a) {
		super(a);
		this.settingsDefinition = settingsDefinition;
	}




	public BF3CheckBox(SettingsDefinition settingsDefinition, Icon icon, boolean selected) {
		super(icon, selected);
		this.settingsDefinition = settingsDefinition;
	}




	public BF3CheckBox(SettingsDefinition settingsDefinition, Icon icon) {
		super(icon);
		this.settingsDefinition = settingsDefinition;
	}




	public BF3CheckBox(SettingsDefinition settingsDefinition, String text, boolean selected) {
		super(text, selected);
		this.settingsDefinition = settingsDefinition;
	}




	public BF3CheckBox(SettingsDefinition settingsDefinition, String text, Icon icon, boolean selected) {
		super(text, icon, selected);
		this.settingsDefinition = settingsDefinition;
	}




	public BF3CheckBox(SettingsDefinition settingsDefinition, String text, Icon icon) {
		super(text, icon);
		this.settingsDefinition = settingsDefinition;
	}




	public BF3CheckBox(SettingsDefinition settingsDefinition, String text) {
		super(text);
		this.settingsDefinition = settingsDefinition;
	}




//	@Override
//	abstract public void updateValue();
	@Override
	public void updateValue() {
		boolean selected = false;
		ValueObject[] valuesObjects = settingsDefinition.getValueObjects();

		if(valuesObjects != null){
			if(this.getActionCommand().equals("soundSystemSubWoofer")){
				String value = valuesObjects[1].getValue().substring(1, 2);
				selected = value.equals("1") ? true : false;
			} else {
				if(valuesObjects[1].getValue().equals("1")){
					selected = true;
				}
			}
		}
		this.setSelected(selected);
	}
	
	@Override
	public void setValue(String value){
		ValueObject[] valueObjects = settingsDefinition.getValueObjects();
		if(valueObjects != null){
			if(this.getActionCommand().equals("soundSystemSubWoofer")){
				String size = valueObjects[1].getValue().substring(0, 1);
				value = size+value;
			}
			valueObjects[1].setValue(value);
		}
	}

}
